//
// CMeshGeom.java
// Copyright (C) 2010  "Naush" <naush _ hotmail _ fr>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>./* ----------------------------------------------------------------------------







package org.ryzom.nel.threed;

import org.ryzom.nel.misc.IStream;

public class CMeshGeom {
  private long swigCPtr;
  protected boolean swigCMemOwn;

  public CMeshGeom(long cPtr, boolean cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = cPtr;
  }

  public static long getCPtr(CMeshGeom obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        nel3dJNI.delete_CMeshGeom(swigCPtr);
      }
      swigCPtr = 0;
    }
  }

  public CMeshGeom() {
    this(nel3dJNI.new_CMeshGeom(), true);
  }

  public void build(SWIGTYPE_p_NL3D__CMesh__CMeshBuild mbuild, long numMaxMaterial) {
    nel3dJNI.CMeshGeom_build(swigCPtr, this, SWIGTYPE_p_NL3D__CMesh__CMeshBuild.getCPtr(mbuild), numMaxMaterial);
  }

  public void setBlendShapes(SWIGTYPE_p_std__vectorT_CBlendShape_t bs) {
    nel3dJNI.CMeshGeom_setBlendShapes(swigCPtr, this, SWIGTYPE_p_std__vectorT_CBlendShape_t.getCPtr(bs));
  }

  public void applyMaterialRemap(SWIGTYPE_p_std__vectorT_int_t remap) {
    nel3dJNI.CMeshGeom_applyMaterialRemap(swigCPtr, this, SWIGTYPE_p_std__vectorT_int_t.getCPtr(remap));
  }

  public void initInstance(CMeshBaseInstance mbi) {
    nel3dJNI.CMeshGeom_initInstance(swigCPtr, this, CMeshBaseInstance.getCPtr(mbi), mbi);
  }

  public boolean clip(SWIGTYPE_p_std__vectorT_NLMISC__CPlane_t pyramid, SWIGTYPE_p_NLMISC__CMatrix worldMatrix) {
    return nel3dJNI.CMeshGeom_clip(swigCPtr, this, SWIGTYPE_p_std__vectorT_NLMISC__CPlane_t.getCPtr(pyramid), SWIGTYPE_p_NLMISC__CMatrix.getCPtr(worldMatrix));
  }

  public void render(IDriver drv, CTransformShape trans, float polygonCount, long rdrFlags, float globalAlpha) {
    nel3dJNI.CMeshGeom_render(swigCPtr, this, IDriver.getCPtr(drv), drv, CTransformShape.getCPtr(trans), trans, polygonCount, rdrFlags, globalAlpha);
  }

  public void renderSkin(CTransformShape trans, float alphaMRM) {
    nel3dJNI.CMeshGeom_renderSkin(swigCPtr, this, CTransformShape.getCPtr(trans), trans, alphaMRM);
  }

  public float getNumTriangles(float distance) {
    return nel3dJNI.CMeshGeom_getNumTriangles(swigCPtr, this, distance);
  }

  public void serial(IStream f) {
    nel3dJNI.CMeshGeom_serial(swigCPtr, this, IStream.getCPtr(f), f);
  }

  public void profileSceneRender(CRenderTrav rdrTrav, CTransformShape trans, float polygonCount, long rdrFlags) {
    nel3dJNI.CMeshGeom_profileSceneRender(swigCPtr, this, CRenderTrav.getCPtr(rdrTrav), rdrTrav, CTransformShape.getCPtr(trans), trans, polygonCount, rdrFlags);
  }

  public SWIGTYPE_p_NLMISC__CAABBoxExt getBoundingBox() {
    return new SWIGTYPE_p_NLMISC__CAABBoxExt(nel3dJNI.CMeshGeom_getBoundingBox(swigCPtr, this), false);
  }

  public CVertexBuffer getVertexBuffer() {
    return new CVertexBuffer(nel3dJNI.CMeshGeom_getVertexBuffer(swigCPtr, this), false);
  }

  public long getNbMatrixBlock() {
    return nel3dJNI.CMeshGeom_getNbMatrixBlock(swigCPtr, this);
  }

  public long getNbRdrPass(long matrixBlockIndex) {
    return nel3dJNI.CMeshGeom_getNbRdrPass(swigCPtr, this, matrixBlockIndex);
  }

  public CIndexBuffer getRdrPassPrimitiveBlock(long matrixBlockIndex, long renderingPassIndex) {
    return new CIndexBuffer(nel3dJNI.CMeshGeom_getRdrPassPrimitiveBlock(swigCPtr, this, matrixBlockIndex, renderingPassIndex), false);
  }

  public long getRdrPassMaterial(long matrixBlockIndex, long renderingPassIndex) {
    return nel3dJNI.CMeshGeom_getRdrPassMaterial(swigCPtr, this, matrixBlockIndex, renderingPassIndex);
  }

  public long getNbBlendShapes() {
    return nel3dJNI.CMeshGeom_getNbBlendShapes(swigCPtr, this);
  }

  public boolean retrieveVertices(Vector_CVector vertices) {
    return nel3dJNI.CMeshGeom_retrieveVertices(swigCPtr, this, Vector_CVector.getCPtr(vertices), vertices);
  }

  public boolean retrieveTriangles(Vector_uint16 indices) {
    return nel3dJNI.CMeshGeom_retrieveTriangles(swigCPtr, this, Vector_uint16.getCPtr(indices), indices);
  }

  public boolean isSkinned() {
    return nel3dJNI.CMeshGeom_isSkinned(swigCPtr, this);
  }

  public void computeBonesId(CSkeletonModel skeleton) {
    nel3dJNI.CMeshGeom_computeBonesId(swigCPtr, this, CSkeletonModel.getCPtr(skeleton), skeleton);
  }

  public void updateSkeletonUsage(CSkeletonModel sm, boolean increment) {
    nel3dJNI.CMeshGeom_updateSkeletonUsage(swigCPtr, this, CSkeletonModel.getCPtr(sm), sm, increment);
  }

  public SWIGTYPE_p_std__vectorT_int_t getSkinBoneUsage() {
    return new SWIGTYPE_p_std__vectorT_int_t(nel3dJNI.CMeshGeom_getSkinBoneUsage(swigCPtr, this), false);
  }

  public SWIGTYPE_p_std__vectorT_NLMISC__CBSphere_t getSkinBoneSphere() {
    return new SWIGTYPE_p_std__vectorT_NLMISC__CBSphere_t(nel3dJNI.CMeshGeom_getSkinBoneSphere(swigCPtr, this), false);
  }

  public boolean supportIntersectSkin() {
    return nel3dJNI.CMeshGeom_supportIntersectSkin(swigCPtr, this);
  }

  public boolean intersectSkin(CTransformShape mi, SWIGTYPE_p_NLMISC__CMatrix toRaySpace, SWIGTYPE_p_float dist2D, SWIGTYPE_p_float distZ, boolean computeDist2D) {
    return nel3dJNI.CMeshGeom_intersectSkin(swigCPtr, this, CTransformShape.getCPtr(mi), mi, SWIGTYPE_p_NLMISC__CMatrix.getCPtr(toRaySpace), SWIGTYPE_p_float.getCPtr(dist2D), SWIGTYPE_p_float.getCPtr(distZ), computeDist2D);
  }

  public void renderSimpleWithMaterial(IDriver drv, SWIGTYPE_p_NLMISC__CMatrix worldMatrix, CMaterial mat) {
    nel3dJNI.CMeshGeom_renderSimpleWithMaterial(swigCPtr, this, IDriver.getCPtr(drv), drv, SWIGTYPE_p_NLMISC__CMatrix.getCPtr(worldMatrix), CMaterial.getCPtr(mat), mat);
  }

  public boolean supportMeshBlockRendering() {
    return nel3dJNI.CMeshGeom_supportMeshBlockRendering(swigCPtr, this);
  }

  public boolean sortPerMaterial() {
    return nel3dJNI.CMeshGeom_sortPerMaterial(swigCPtr, this);
  }

  public long getNumRdrPassesForMesh() {
    return nel3dJNI.CMeshGeom_getNumRdrPassesForMesh(swigCPtr, this);
  }

  public long getNumRdrPassesForInstance(CMeshBaseInstance inst) {
    return nel3dJNI.CMeshGeom_getNumRdrPassesForInstance(swigCPtr, this, CMeshBaseInstance.getCPtr(inst), inst);
  }

  public void beginMesh(CMeshGeomRenderContext rdrCtx) {
    nel3dJNI.CMeshGeom_beginMesh(swigCPtr, this, CMeshGeomRenderContext.getCPtr(rdrCtx), rdrCtx);
  }

  public void activeInstance(CMeshGeomRenderContext rdrCtx, CMeshBaseInstance inst, float polygonCount, SWIGTYPE_p_void vbDst) {
    nel3dJNI.CMeshGeom_activeInstance(swigCPtr, this, CMeshGeomRenderContext.getCPtr(rdrCtx), rdrCtx, CMeshBaseInstance.getCPtr(inst), inst, polygonCount, SWIGTYPE_p_void.getCPtr(vbDst));
  }

  public void renderPass(CMeshGeomRenderContext rdrCtx, CMeshBaseInstance inst, float polygonCount, long rdrPass) {
    nel3dJNI.CMeshGeom_renderPass(swigCPtr, this, CMeshGeomRenderContext.getCPtr(rdrCtx), rdrCtx, CMeshBaseInstance.getCPtr(inst), inst, polygonCount, rdrPass);
  }

  public void endMesh(CMeshGeomRenderContext rdrCtx) {
    nel3dJNI.CMeshGeom_endMesh(swigCPtr, this, CMeshGeomRenderContext.getCPtr(rdrCtx), rdrCtx);
  }

  public boolean getVBHeapInfo(SWIGTYPE_p_unsigned_int vertexFormat, SWIGTYPE_p_unsigned_int numVertices) {
    return nel3dJNI.CMeshGeom_getVBHeapInfo(swigCPtr, this, SWIGTYPE_p_unsigned_int.getCPtr(vertexFormat), SWIGTYPE_p_unsigned_int.getCPtr(numVertices));
  }

  public void computeMeshVBHeap(SWIGTYPE_p_void dst, long indexStart) {
    nel3dJNI.CMeshGeom_computeMeshVBHeap(swigCPtr, this, SWIGTYPE_p_void.getCPtr(dst), indexStart);
  }

  public boolean hasMeshVertexProgram() {
    return nel3dJNI.CMeshGeom_hasMeshVertexProgram(swigCPtr, this);
  }

  public IMeshVertexProgram getMeshVertexProgram() {
    long cPtr = nel3dJNI.CMeshGeom_getMeshVertexProgram(swigCPtr, this);
    return (cPtr == 0) ? null : new IMeshVertexProgram(cPtr, false);
  }

}
